home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / CDTV / cdtvtools-11 / system / getprefs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-24  |  3.2 KB  |  116 lines

  1. /***********************************************************************
  2. ***
  3. *** CDTV - Read Preferences
  4. ***
  5. ***     Copyright (C) 1990 Commodore-Amiga, Inc.
  6. ***     Permission granted for use in CDTV applications.
  7. ***     Author: Carl Sassenrath, Ukiah, CA  (30-DEC-90)
  8. ***
  9. ************************************************************************
  10. ***
  11. ***     What:
  12. ***       This example will read the CDTV preferences data
  13. ***       structure from bookmark memory.  If the structure
  14. ***       cannot be found, an error will result.
  15. ***
  16. ***     Notes:
  17. ***       1. Read the notes in cdtvprefs.h!
  18. ***       2. Currently tested with Manx C compiler only.
  19. ***
  20. ***
  21. ***********************************************************************/
  22.  
  23. #include <exec/types.h>
  24. #include <exec/io.h>
  25. #include <devices/bookmark.h>
  26. #include <devices/cdtvprefs.h>
  27.  
  28. extern  struct  IOStdReq *CreateStdIO();
  29. extern  struct  MsgPort  *CreatePort();
  30. struct  IOStdReq *IOReq1 = NULL;
  31. struct  MsgPort  *IOPort = NULL;
  32. struct  CDTVPrefs ThePrefs;
  33.  
  34. char    AssertFail[] = "Assertion failed (MUST)";
  35. #define MUST(expr)  if (!(expr)) Quit(AssertFail);
  36.  
  37. /***********************************************************************
  38. ***
  39. ***  Main
  40. ***
  41. ***********************************************************************/
  42. main(argc,argv)
  43.         int argc;
  44.         char *argv[];
  45. {
  46.         int err;
  47.  
  48.         printf("CDTV Read Preferences Example (30-Dec-90)\n");
  49.  
  50.         Init();
  51.  
  52.         if (DoIOR(IOReq1, CMD_READ, 0, sizeof(ThePrefs), &ThePrefs))
  53.                 Quit("CMD_READ failed");
  54.  
  55.         printf("Prefs contents: %d %d %d %d 0x%x\n",
  56.                 ThePrefs.DisplayX,
  57.                 ThePrefs.DisplayY,
  58.                 ThePrefs.Language,
  59.                 ThePrefs.AudioVol,
  60.                 ThePrefs.Flags);
  61.  
  62.         Quit(0);
  63. }
  64.  
  65. /***********************************************************************
  66. ***
  67. ***  Init -- initialize program and structures
  68. ***
  69. ***********************************************************************/
  70. Init()
  71. {
  72.         MUST(IOPort = CreatePort(0,0));
  73.         MUST(IOReq1 = CreateStdIO(IOPort));
  74.  
  75.         if (OpenDevice("bookmark.device",BID_CDTVPREFS,IOReq1,0))
  76.                 Quit("Bookmark device will not open");
  77. }
  78.  
  79. /***********************************************************************
  80. ***
  81. ***  Quit -- exit program and clean-up.  Return an error if needed.
  82. ***
  83. ***********************************************************************/
  84. Quit(s)
  85.         char *s;        /* error message */
  86. {
  87.         if (IOReq1)
  88.         {
  89.                 if (IOReq1->io_Device) CloseDevice(IOReq1);
  90.                 DeleteStdIO(IOReq1);
  91.         }
  92.         if (IOPort)     DeletePort(IOPort);
  93.         if (s) {printf("\nERROR: %s\n",s); exit(40);}
  94.         else exit(0);
  95. }
  96.  
  97. /***********************************************************************
  98. ***
  99. ***  DoIOR -- execute a device command
  100. ***
  101. ***********************************************************************/
  102. DoIOR(req,cmd,off,len,data)
  103.         struct IOStdReq *req;
  104.         int cmd;
  105.         long off;
  106.         long len;
  107.         APTR data;
  108. {
  109.         req->io_Command = cmd;
  110.         req->io_Offset = off;
  111.         req->io_Length = len;
  112.         req->io_Data   = data;
  113.         return DoIO(req);
  114. }
  115.  
  116.